/* 欧拉计划 euler
Multiples of 3 and 5
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5,6 and 9.
The sum of these mulitiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
--------------------------------------------------------------------------------------
3或5的倍数
在小于10的自然数中，3或5的倍数有3,5,6和9，这些之和是23.
求小于1000的自然数中所有3和5的倍数之和 answer 233168
*/
#include <iostream>
using namespace std;
#define MAX 10

#define PLAN_1 0
#define PLAN_2 1
int main(int argc, char const *argv[])
{
#if PLAN_1 // 时间复杂度O(n) 空间复杂度O(1)
    int sum = 0;
    for(int i = 0; i < MAX; i++){
        if(i % 3 == 0 || i % 5 == 0){
            sum += i;
        }
    }
    cout<<"the sum of all the multiples of 3 or 5 below "<< MAX << " = "<< sum <<endl;
#elif PLAN_2 // 时间复杂度O(1) 空间复杂度O(1)
    int multiles_3 = (3 + 999) * 333 / 2;
    int multiles_5 = (5 + 995) * 199 / 2;
    int multiles_15 = (15 + 990) * 66 / 2;
    int sum = multiles_3 + multiles_5 - multiles_15;
    cout << "the sum of all the multiples of 3 or 5 below " << MAX << " = " << sum << endl;
#endif
    return 0;
}
